<template>
  <c-card isAffix>
    <div class="prototype-generator">
      <upload-img isPreview v-model="uploadObj" @on-preview="initData"></upload-img>
      <div class="wallpaper-temp">
        <img v-if="url" class="preview-img" :src="url" />
      </div>
    </div>
  </c-card>
</template>

<script setup name="prototype-generator">
import { ref } from 'vue';
import UploadImg from '@/components/upload/upload-img.vue';
import { usePhoneCanvas } from '@/hooks/usePhoneCanvas/index.js';

const uploadObj = ref({ url: '' });

const url = ref('');

const initData = async () => {
  const { toDataURL } = usePhoneCanvas({ imgUrl: uploadObj.value.url });
  url.value = await toDataURL();
};
</script>

<style lang="scss" scoped>
.prototype-generator {
  display: flex;
  height: 100%;
}
.wallpaper-temp {
  // width: 375px;
  margin-left: 20px;
  width: auto;
  height: 100%;
  aspect-ratio: 9/16;
  border: 1px solid #999;

  .preview-img {
    width: 100%;
    height: 100%;
  }
}
</style>
